<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
		<title>询价物料</title>
		<link rel="stylesheet" href="fonts/iconfont.css" />
		<link rel="stylesheet" href="css/font.css" />
		<link rel="stylesheet" href="css/weui.min.css" />
		<link rel="stylesheet" href="css/jquery-weui.min.css" />
		<link rel="stylesheet" href="css/mui.css" />
		<link rel="stylesheet" href="css/animate.css" />
		<link rel="stylesheet" href="css/pages/xunjia_wuliao.css" />
		<script>
			(function(doc, win) {
				var docEl = doc.documentElement,
					resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
					recalc = function() {
						var clientWidth = docEl.clientWidth;
						if(!clientWidth) return;
						docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
					};

				if(!doc.addEventListener) return;
				win.addEventListener(resizeEvt, recalc, false);
				doc.addEventListener('DOMContentLoaded', recalc, false);
			})(document, window);
		</script>
	</head>
	
	<body>
		<div class="mui-content mui-scroll-wrapper">
    	    <header>
				<div class="titlebar reverse" style="background-color:#438EB9;">
					<a id="tryBack" style="color:white ;padding-left:10px;">
						<i class="iconfont">&#xe640;</i>
					</a>
					<h1>订单列表</h1> 
				</div>
			</header>
			<div id="refreshContainer" class="mui-scroll" style="bottom: 0; padding-top: 1rem;">
				<ul id="art" class="mui-table-view mui-table-view-chevron">
					
				</ul>
			</div>
    	</div>
		

		<script src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/add.js"></script>
		<script src="js/mui.min.js"></script>
		<script>
			var pageC = 1;
			mui.init({
				pullRefresh: {
					container: "#refreshContainer", //下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
					down: {
						style:'circle',//必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
						color:'#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
						auto: false, //可选,默认false.首次加载自动上拉刷新一次
						callback: refreshData //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
					},
					up: {
						height: 0, //可选.默认50.触发上拉加载拖动距离
						auto: true, //可选,默认false.自动上拉加载一次 
						contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
						contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
						callback: loadMoreData //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
					}
				}
			});

			//刷新数据  重新调用接口
			function refreshData() {
				window.location = 'details.html';
				mui('#refreshContainer').pullRefresh().endPulldown();
			}
			
			//请求下一页数据
			function loadMoreData() {
				var StoreId = localStorage.getItem("StoreId");
				var ptId = localStorage.getItem("ptId");
				window.token = localStorage.getItem("token");
				
				if(ptId == "alPt") {
					var status = "已打印";
				} else if(ptId == "notPt") {
					var status = "打印中";
				}
				
				mui.ajax("http://api.jhjnzx.com/api/user/GetData", {
					data: {
						procName: "GetStoreOrders",
						args: JSON.stringify({
							StoreId: StoreId,//此处应取保存的StoreId
							status: status,
							CurrentPage: pageC,
							PageSize: 10
						}),
					},
					method: "get",
					async: false,
					headers: {
						"auth": window.token
					}, //通过请求头来发送token，放弃了通过cookie的发送方式

					success: function(data) {
						returnData = JSON.parse(data);
						var element = document.getElementById("art");
//						alert(pageC);
						for(var i = 0; i < returnData.length; i++) {
							var str = returnData[i]["CreateTime"];
							//alert(str); 
							var str2 = str.substring(0, 10);
							var str3 = str.substring(11, 19);
							var price = returnData[i]["TotalAmount"];
							
							para = document.createElement("li");
							para.style = 'border-bottom:1px solid #000';
							para.className = 'weui_cell';
							para.setAttribute("id", returnData[i]["OrderId"]);
							para.setAttribute("onclick", "getId(this)");
							para.innerHTML =
								'<div class="weui_cell_bd weui_cell_primary">' +
									'<div class="wuliao-title" style="text-align: center;">' +
									'<label>订单编号:</label>' +
									'<label>' + returnData[i]["OrderNumber"] + '</label>' +
									'<span style="padding-left: 1rem;">' + str2 + '</span>' +
									'</div>' + 
									'<hr style="opacity: 0.1;" />' +
									'<div class="detail clearfix" style="padding-top: 0.5rem;">' +
									'<span class="date">下单时间:' + str3 + '</span>' +
									'<span class="result">Tel：<label style="color:black;">' + returnData[i]["ClientTelephone"] + '</label></span>' +
									'</div>' +
									'<div class="detail clearfix">' +
									'<span class="date">地址:' + returnData[i]["ClientAddress"] + '</span>' +
									'</div>' +
									'<div class="detail clearfix">' +
									'<span class="result">总价：<label style="color:red;">$ ' + price + '</label></span>' +
									'</div>' +
								'</div>';
							element.appendChild(para);
						}
					}
				});
				mui('#refreshContainer').pullRefresh().endPullupToRefresh();
				pageC = pageC + 1;
			}

			mui.plusReady(function() {
				var StoreId = localStorage.getItem("StoreId");
				if(StoreId == null) {
					alert("进入到登出阶段");
					mui.openWindow({
						url: 'login.html'
					});
				}
			});

			tryBack.onclick = function() {
				var tryBack = document.getElementById("tryBack");
				window.location = 'tasks.html';
			}

			function getId(obj) {　　　　　　　　
				var orderId = obj.id;
//				alert(orderId);
				localStorage.setItem("orderId", orderId);
				window.location = 'order.html';
			}
		</script>
	</body>

</html>